import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
//svg
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import path from 'path'
//mock
import { viteMockServe } from 'vite-plugin-mock'
// https://vite.dev/config/
//@ts-ignore
export default ({ command }) => {
  return {
    plugins: [
      vue(),
      vueDevTools(),
      //挂载全局变量
      createSvgIconsPlugin({
        iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
        symbolId: 'icon-[dir]-[name]'
      }),
      //mock
      viteMockServe({
        enable: command === 'serve', // 替换为正确的配置项
        logger: true // 是否打印日志
      })
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    //挂载scss全局变量
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@use "@/styles/variable.scss" as *;`,
          javascriptEnabled: true
        }
      }
    }
  }
}
